<?php
namespace Admin\Controller;

class IndexController extends AdminBaseController
{
   public function main()
    {
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        }
        $this->display('index/main');
    } 
    
    public function index(){
        if(session('auid')==null){
            $this->display('index/login');
            exit();
        } else {
            $this->display('index/index');
        }
    }
    
    public function login(){
        $account=I('username','');
        $paswd=I('password','');
        $cond['account']=$account;
        $cond['passwd']=md5($paswd);
        $admin=M('Admin')->where($cond)->select();
        if(empty($admin)){
            $this->display('index/login');
            exit();
        }
        session('auid',$admin[0]['id']);
        session('nickname',$admin[0]['nickname']);
        
        //今日交易总额
        
        $datecondi['createdate'] = array(array('egt',date("Y-m-d").' 00:00:00'),array('elt',date('y-m-d H:m:s',time())));
        $daytransmoney=M('DomainTranslog')->where($datecondi)->sum('totel_price');
        if(empty($daytransmoney)){
            $daytransmoney=0;
        }
        //今日借款总额
        $datecondi['status']=array('neq',4);//投标中的不算
        $dayvestermoney=M('CredFlow')->where($datecondi)->sum('money');
        if(empty($dayvestermoney)){
            $dayvestermoney=0;
        }
        //等待还息借款总额
        $ratevestermoney=M('CredFlow')->where('status in(1,3)')->sum('money');
        //历史交易总额
        $transmoney=M('DomainTranslog')->sum('totel_price');
        //历史借款总额
        $vestermoney=M('CredFlow')->where('status!=4')->sum('money');
        $this->assign('daytransmoney',$daytransmoney);
        $this->assign('dayvestermoney',$dayvestermoney);
        $this->assign('ratevestermoney',$ratevestermoney);
        $this->assign('transmoney',$transmoney);
        $this->assign('vestermoney',$vestermoney);
        $this->display('index/main');
    }
}